//获取XMLDocument对象
function getXMLDocument() {
	var xDoc = null;
	if (document.implementation && document.implementation.createDocument) {
		xDoc = document.implementation.createDocument("", "", null);//Mozilla/Safari
	} else if (typeof ActiveXObject != "undefined") {
		var msXmlAx = null;
		try {
			msXmlAx = new ActiveXObject("Msxml2.DOMDocument");//较新版本的IE浏览器
		} catch (e) {
			msXmlAx = new ActiveXObject("Msxml.DOMDocument");//较老版本的IE浏览器
		}
		xDoc = msXmlAx;
	}
	if (xDoc == null || typeof xDoc.load == "undefined") {
		xDoc = null;
	}
	return xDoc;
}

//获取XMLHttpRequest对象
function getXMLHttpRequest() {
	var xRequest = null;
	if (window.XMLHttpRequest) {
		xRequest = new XMLHttpRequest();//Mozilla/Safari
	} else if (typeof ActiveXObject != "undefined") {
		xRequest = new ActiveXObject("Microsoft.XMLHTTP");//IE
	}
	return xRequest;
}

//向服务器发送数据
function sendRequest(url, params, HttpMethod) {
	if (!HttpMethod) {
		HttpMethod = "POST";
	}
	var req = getXMLHttpRequest();
	if (req) {
		req.open(HttpMehtod, url, true);
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		req.send(params);
	}
}

//使用回调处理函数
var READY_STATE_UNINITIALIZED = 0;
var READY_STATE_LOADING = 1;
var READY_STATE_LOAD = 2;
var READY_STATE_INTERACTIVE = 3;
var READY_STATE_COMPLETE = 4;
var req;

function sendRequest(url, params, HttpMethod) {
	if (!HttpMethod) {
		HttpMethod = "GET";
	}
	var req = getXMLHttpRequest();
	if (req) {
		req.onreadystatechange = onReadyStateChange;
		req.open(HttpMehtod, url, true);
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		req.send(params);
	}
}

function onReadyStateChange() {
	var ready = req.readyStates;
	var data = null;
	if (ready == READY_STATE_COMPLETE) {
		data = req.responseText;
	} else {
		data = "loading...[" + ready + "]";
	}
	//...do something with the data
}